import React from 'react';
import { Card, Form, Button } from 'antd';
import { connect } from 'umi';
import { withRoutePage } from '@/utils/enhanceUtils';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import StarRule from './StarRule';

const ManualGradeRule = ({ currentUser, ...props }) => {
    const [tab, setTab] = React.useState('tab1');

    // 新增按钮放到了这一层
    const [visible, setVisible] = React.useState(false); // 弹窗
    const [editId, setEditId] = React.useState(); // 编辑id
    const [isView, setIsView] = React.useState(false); // 是否为查看

    const propsMap = {
        visible,
        setVisible,
        editId,
        setEditId,
        isView,
        setIsView,
        companyId: currentUser.companyId,
        ...props
    };

    const tabList = [
        {
            key: 'tab1',
            tab: '星级评分制'
        }
    ];

    const contentList = {
        tab1: <StarRule {...propsMap} />
    };

    const extraButton = (
        <Button
            type="primary"
            style={{ marginTop: 12 }}
            onClick={() => {
                setEditId(null);
                setVisible(true);
                setIsView(false);
            }}
        >
            新增
        </Button>
    );

    const handleTabChange = key => {
        setVisible(false);
        setTab(key);
    };

    return (
        <PageHeaderWrapper>
            <Card bordered={false} tabList={tabList} onTabChange={handleTabChange} tabBarExtraContent={extraButton}>
                {contentList[tab]}
            </Card>
        </PageHeaderWrapper>
    );
};

export default withRoutePage(
    connect(({ user }) => ({
        currentUser: user.currentUser
    }))(Form.create()(ManualGradeRule))
);
